local extension = Package:new("starjade_cards", Package.CardPack)
extension.extensionName = "zzz_zyg_cards"
Fk:loadTranslationTable{
  ["starjade_cards"] = "星玉游戏牌",
}

local U = require "packages/utility/utility"

--[[local damage_nature_table = {
  [fk.Waterdamage] = "water_damage",
}]]
extension:addCards{
  Fk:cloneCard("jink", Card.Heart, 2),
  Fk:cloneCard("jink", Card.Heart, 4),
  Fk:cloneCard("jink", Card.Heart, 9),
  Fk:cloneCard("jink", Card.Heart, 11),
  Fk:cloneCard("jink", Card.Diamond, 2),
  Fk:cloneCard("jink", Card.Diamond, 3),
  Fk:cloneCard("jink", Card.Diamond, 6),
  Fk:cloneCard("jink", Card.Diamond, 10),
  Fk:cloneCard("jink", Card.Diamond, 11),
  Fk:cloneCard("peach", Card.Heart, 3),
  Fk:cloneCard("peach", Card.Heart, 7),
  Fk:cloneCard("peach", Card.Heart, 8),
  Fk:cloneCard("peach", Card.Heart, 12),
}

-- 韬略表
local TaolueCards = {}
local function addTaolueCard(c)
  extension:addCard(c)
  table.insert(TaolueCards, c)
end

-- 加韬略
local addTaolueSkill = fk.CreateActiveSkill{
  name = "military_strategy_add&",
  target_num = 0,
  min_card_num = 1,
  can_use = Util.FalseFunc,
  card_filter = function (self, to_select, selected)
    if #selected > 0 then return false end
    local card = Fk:getCardById(to_select)
    return card:getMark("@@military_strategy") > 0
  end,
  target_filter = Util.FalseFunc,
  on_use = Util.FalseFunc,
}
Fk:addSkill(addTaolueSkill)

--- 获取一名角色的韬略数
---@param player ServerPlayer @ 目标角色
---@return integer
local function getTaolueNum(player)
  return #player:getPile("military_strategy") or 0
end

--- 获取一名角色的韬略牌
---@param player ServerPlayer @ 目标角色
---@return Card[]
local function getTaolue(player)
  return player:getPile("military_strategy") or {}
end

--- 选择牌加入韬略
---@param player ServerPlayer @要操作的玩家
---@param max_num integer? @最大数 暂未实现，留着先
---@param min_num integer? @最小数
local function SelectTaolue(player, max_num, min_num)
  local room = player.room
  local able_num = 2-getTaolueNum(player)
  max_num, min_num = max_num and math.max(able_num, max_num) or 1, min_num or 1
  local success, ret = room:askForUseActiveSkill(player, addTaolueSkill.name, "#addtaolue-prompt", true)
  if success then
    local cards = ret.cards
    if #cards == 0 then return end
    return cards
  end
end

--- 将指定牌加入韬略
---@param player ServerPlayer @ 操作者
---@param cards Card[] @ 指定的牌
---@param skillname string @ 技能名
local function addTaolue(player, cards, skillname)
  player.room:moveCardTo(cards, Card.PlayerSpecial, player, fk.ReasonJustMove, skillname, "military_strategy", true, player.id, nil)
end

-- 韬略三段式
local taolue_trigger = fk.CreateTriggerSkill{
  name = "#military_strategy_trigger&",
  priority = 0.001,
  anim_type = "special",
  derived_piles = "military_strategy",
  events = {fk.EventPhaseStart, fk.DamageCaused, fk.AfterCardUseDeclared},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Finish
      elseif event == fk.DamageCaused then
        return data.to ~= player and getTaolueNum(data.to) > 0
      else
        return player:getMark("military_strategy_DMG-turn") > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local cards = SelectTaolue(player)
      if cards then
        self.cost_data = cards
        return true
      end
    elseif event == fk.DamageCaused then
      local taolues = getTaolue(data.to)
      local cards, chioce = U.askforChooseCardsAndChoice(player, taolues, {"OK"}, self.name, "#military_strategy_reduce_prompt:"..data.to.id, {"Cancel"}, 1, data.damage)
      if chioce == "OK" and #cards > 0 then
        self.cost_data = cards
        return true
      end
    else
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    if event == fk.EventPhaseStart then
      addTaolue(player, self.cost_data, self.name)
    elseif event == fk.DamageCaused then
      local cards = self.cost_data
      data.damage = math.max((data.damage - #cards), 0) or 0
      player.room:throwCard(cards, self.name, data.to, player)
    else
      data.additionalDamage = (data.additionalDamage or 0) + player:getMark("military_strategy_DMG-turn")
      player.room:setPlayerMark(player, "military_strategy_DMG-turn", 0)
    end
  end,
}

-- 韬略主动技
local taolue_skill = fk.CreateActiveSkill{
  name = "military_strategy&",
  target_num = 0,
  min_card_num = 1,
  expand_pile = "military_strategy",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select)
    return Self:getPileNameOfId(to_select) == "military_strategy"
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    room:addPlayerMark(from, "military_strategy_DMG-turn", #effect.cards)
  end,
}
taolue_skill:addRelatedSkill(taolue_trigger)
Fk:addSkill(taolue_skill)

-- 开局发韬略技能
local taolue_rule = fk.CreateTriggerSkill{
  name = "#taolue_rule",
  priority = 0.001,
  global = true,

  refresh_events = {fk.GamePrepared},
  can_refresh = function(self, event, target, player, data)
    return not table.contains(player.room.disabled_packs, "starjade_cards")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:handleAddLoseSkills(p, taolue_skill.name, nil, false, true)
    end
    for _, card in ipairs(Fk.packages["starjade_cards"].cards) do
      if table.contains(TaolueCards, card) then
        room:setCardMark(card, "@@military_strategy", 1)
      end
    end
  end,
}
Fk:addSkill(taolue_rule)

-- 韬略翻译区
Fk:loadTranslationTable{
  ["military_strategy_add&"] = "韬略",
  ["@@military_strategy"] = "韬略",
  ["military_strategy"] = "韬略",
  ["#addtaolue-prompt"] = "韬略：可以将一张“韬略”牌放置于体力牌旁",
  ["#military_strategy_trigger&"] = "韬略",
  ["military_strategy&"] = "韬略",
  ["#taolue_rule"] = "韬略",
  ["military_strategy_DMG-turn"] = "韬略",
  ["#military_strategy_reduce_prompt"] = "韬略：可以令此伤害减少任意点，然后弃置其体力牌旁的等量张“韬略”牌",
  [":military_strategy&"] = "结束阶段，你可以将一张“韬略”牌置于体力牌旁（至多放置两张）；"
  .."出牌阶段限一次，你可以弃置体力牌旁的任意张“韬略”牌。若如此做，你本回合下一次使用牌时，此牌造成的伤害+X（X为你以此法弃置的牌数）；"
  .."当你对体力牌旁有“韬略”牌的其他角色造成伤害时，你可以令此伤害减少任意点，然后弃置其体力牌旁的等量张“韬略”牌。"
}

local slash = Fk:cloneCard("slash")
local waterSlashSkill = fk.CreateActiveSkill{
  name = "water__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = "water_damage",
      skillName = self.name
    })
  end
}
local WaterDamageSkill = fk.CreateTriggerSkill{
  name = "water_damage_skill",
  global = true,
  priority = 0,
  mute = true,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if target == player and data.card and not data.chain then
      return data.damage > 1 and data.card.trueName == "slash" and data.damageType == "water_damage" 
    end
  end,
  on_cost = function (self, event, target, player, data)
    local to = data.to
    if not to.dead then
      return #player.room:getAlivePlayers() > 1
    end
    return 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local from = data.from
    local sputtering = data.damage - 1
    data.damage = 1
    local available = table.filter(room:getOtherPlayers(to), function(p)
      return not p.dead and not p.chained and p ~= from
    end)
    available = table.map(available, Util.IdMapper)
    if sputtering < #available and #available > 0 then
      local aims = {}
      local targets
      for i = 1, sputtering do
        if #aims >= sputtering then break end
        targets = table.filter(room:getOtherPlayers(to), function(p)
          return table.every(room:getOtherPlayers(to), function(p2)
            return to:distanceTo(p) <= to:distanceTo(p2) or table.contains(aims, p2.id) or p2.chained or p2 == from
            end) and not table.contains(aims, p.id) and not p.chained and p ~= from
          end)
        targets = table.map(targets, Util.IdMapper)
        if #targets > 0 and #targets <= sputtering - #aims then
          for _, aim1 in ipairs(targets) do
            table.insert(aims, aim1)
          end
        elseif #targets > 0 and sputtering - #aims > 0 and #targets > sputtering - #aims then
          local choose_num =  sputtering - #aims
          local choose = room:askForChoosePlayers(from, targets, choose_num, choose_num, "#water_damage_choose:::"..choose_num, self.name, false)
          if #choose > 0 then
            for _, aim2 in ipairs(choose) do
              table.insert(aims, aim2)
            end
          end
        end
      end
      if #aims > 0 then
        for _, aim3 in ipairs(aims) do
          room:addPlayerMark(room:getPlayerById(aim3), "waterdamage-phase", 1)
        end
      end
    elseif sputtering >= #available then
      if #available > 0 then
        for _, aim in ipairs(available) do
          room:addPlayerMark(room:getPlayerById(aim), "waterdamage-phase", 1)
        end
      end
    end
  end,
}
local WaterSputtering = fk.CreateTriggerSkill{
  name = "water_sputtering",
  global = true,
  mute = true,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if not data.from then return end
    if not data.from.dead and data.damageType == "water_damage" then
      return table.find(player.room:getOtherPlayers(data.to), function(p)
        return p:getMark("waterdamage-phase") > 0 and p:isAlive()
      end)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    local to = data.to
    local aims = {}
    local targets = table.filter(room:getOtherPlayers(to), function(p)
      return p:getMark("waterdamage-phase") > 0 and p:isAlive()
    end)
    targets = table.map(targets, Util.IdMapper)
    if #targets > 0 then
      for _, id in ipairs(targets) do
        table.insert(aims, id)
        room:removePlayerMark(room:getPlayerById(id), "waterdamage-phase", 1)
      end
    end
    if #aims > 0 and not from.dead then
      for _, aim in ipairs(aims) do
        room:damage{
          from = data.from,
          to = room:getPlayerById(aim),
          damageType = "water_damage",
          damage = 1,
        }
        if from.dead then break end
      end
    end
  end
}
Fk:addSkill(WaterDamageSkill)
Fk:addSkill(WaterSputtering)
local waterSlash = fk.CreateBasicCard{
  name = "water__slash",
  skill = waterSlashSkill,
  is_damage_card = true,
  suit = Card.Diamond,
  number = 13,
}
Fk:loadTranslationTable{
  ["water__slash"] = "水杀",
  ["water_damage_skill"] = "水杀",
  ["water_damage"] = "水属性伤害",
  [":water__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：攻击范围内的一名角色<br /><b>效果</b>：对目标角色造成1点水属性伤害。<br/>"..
  "<font color='grey'><small>（一名角色受到水【杀】造成的不为连环伤害的水属性伤害时，若此伤害大于1，则防止多余伤害，改为由来源对依次受伤角色距离由近到"..
  "远的非连环其他角色造成1点水属性伤害，伤害目标数等于以此法防止的多余伤害数，不足则改为所有受伤角色以外的非连环其他角色）。</small></font>",
  ["#water_damage_choose"] = "水杀：请选择 %arg 名角色",
}
extension:addCards{
  waterSlash:clone(Card.Spade, 3),
  waterSlash:clone(Card.Spade, 7),
  waterSlash:clone(Card.Spade, 8),
  waterSlash:clone(Card.Spade, 9),
  waterSlash:clone(Card.Club, 5),
  waterSlash:clone(Card.Club, 7),
  waterSlash:clone(Card.Club, 8),
  waterSlash:clone(Card.Club, 9),
}
local shotSlashSkill = fk.CreateActiveSkill{
  name = "sjade_shot__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    local player = Fk:currentRoom():getPlayerById(to_select)
    local from = Fk:currentRoom():getPlayerById(user)
    return from ~= player and from:distanceTo(player) >= 3
  end,
  target_filter = function(self, to_select, selected, _, card, extra_data)
    local count_distances = not (extra_data and extra_data.bypass_distances)
    if #selected < self:getMaxTargetNum(Self, card) then
      local player = Fk:currentRoom():getPlayerById(to_select)
      return self:modTargetFilter(to_select, selected, Self.id, card, count_distances) and
      (
        #selected > 0 or
        Self.phase ~= Player.Play or
        (extra_data and extra_data.bypass_times) or
        self:withinTimesLimit(Self, Player.HistoryPhase, card, "slash", player)
      )
    end
  end,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name
    })
  end
}
local shotSlash = fk.CreateBasicCard{
  name = "sjade_shot__slash",
  skill = shotSlashSkill,
  is_damage_card = true,
  suit = Card.Diamond,
  number = 13,
}
Fk:loadTranslationTable{
  ["sjade_shot__slash_skill"] = "射杀",
  [":sjade_shot__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名距离不小于3的其他角色<br /><b>效果</b>：对目标角色造成1点伤害。<br/>",
}
addTaolueCard(shotSlash:clone(Card.Heart, 10))
addTaolueCard(shotSlash:clone(Card.Diamond, 4))
addTaolueCard(shotSlash:clone(Card.Diamond, 7))
addTaolueCard(shotSlash:clone(Card.Diamond, 8))
addTaolueCard(shotSlash:clone(Card.Diamond, 9))

local talismanSkill = fk.CreateActiveSkill{
  name = "sjade__talisman_skill",
  prompt = "#sjade__talisman_skill",
  can_use = function(self, player, card, extra_data)
    return not player:isProhibited(player, card) and self:withinTimesLimit(player, Player.HistoryTurn, card, "talisman", player)
  end,
  on_use = function(_, _, use)
    if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then
      use.tos = { { use.from } }
    end
  end,
  on_effect = function(_, room, effect)
    local to = Fk:currentRoom():getPlayerById(effect.to)
    local choices = {"fire__slash", "thunder__slash", "ice__slash", "water__slash", "damage_add"}
    local choice = Fk:currentRoom():askForChoice(to, choices, "sjade__talisman_skill")
    if #choice > 0 then
      if choice == "damage_add" then
        Fk:currentRoom():addPlayerMark(to, "talisman_buff-turn", 1)
      else 
        Fk:currentRoom():setPlayerMark(to, "talisman_element-turn", choice)
      end
    end
  end
}
local talismanEffect = fk.CreateTriggerSkill{
  name = "sjade__talisman_effect",
  global = true,
  mute = true,
  priority = 0,
  events = { fk.AfterCardUseDeclared},
  can_trigger = function(_, event, target, player, data)
    if target == player and player:getMark("talisman_buff-turn") > 0 then
      if data.card.trueName == "slash" then
        return (
          data.card.name == "fire__slash" or
          data.card.name == "thunder__slash" or
          data.card.name == "ice__slash" or
          data.card.name == "water__slash" 
      )
      end
    end
  end,
  on_trigger = function(_, event, _, player, data)
    local x = player:getMark("talisman_buff-turn")
    if x > 0 then
      data.additionalDamage = (data.additionalDamage or 0) + x
      data.extra_data = data.extra_data or {}
      player.room:setPlayerMark(player, "talisman_buff-turn", 0)
    end
  end
}
local talismanElement = fk.CreateTriggerSkill{
  name = "sjade__talisman_element",
  global = true,
  mute = true,
  priority = 0.001,
  events = { fk.AfterCardUseDeclared },
  can_trigger = function(self, _, target, player, data)
    if target == player and data.card.trueName == "slash" then
      return player:getMark("talisman_element-turn") ~= 0 and (
        data.card.name == "slash" or
        data.card.name == "sjade_shot__slash" or
        data.card.name == "stab__slash"
      )
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local card = Fk:cloneCard(player:getMark("talisman_element-turn"), data.card.suit, data.card.number)
    for k, v in pairs(data.card) do
      if card[k] == nil then
        card[k] = v
      end
    end
    if data.card:isVirtual() then
      card.subcards = data.card.subcards
    else
      card.id = data.card.id
    end
    card.skillNames = data.card.skillNames
    card.skillName = "sjade__talisman_skill"
    data.card = card
    data.card.name = player:getMark("talisman_element-turn")
    player.room:setPlayerMark(player, "talisman_element-turn", 0)
  end,
}
Fk:addSkill(talismanEffect)
Fk:addSkill(talismanElement)
local talisman = fk.CreateBasicCard{
  name = "sjade__talisman",
  skill = talismanSkill,
  suit = Card.Diamond,
  number = 13,
}
Fk:loadTranslationTable{
  ["sjade__talisman_skill"] = "符",
  ["#sjade__talisman_skill"] = "选择一项效果",
  ["damage_add"] = "令下一张属性杀的伤害+1",
  [":sjade__talisman"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：你<br /><b>效果</b>：选择一项：<br/>1.令本回合使用的下一张普通【杀】变为一种属性【杀】；<br/>"..
  "2.令本回合使用的下一张属性杀造成的伤害+1。<br/>",
}
extension:addCards{
  talisman:clone(Card.Spade, 6),
  talisman:clone(Card.Heart, 5),
  talisman:clone(Card.Heart, 6),
  talisman:clone(Card.Club, 6),
  talisman:clone(Card.Diamond, 5),
}
local floodAttackCardSkillViewAs = fk.CreateActiveSkill{
  name = "flood_attack_skill_viewas",
  can_use = function() return false end,
  target_num = 0,
  min_card_num = 1,
  max_card_num = 3,
  card_filter = function(self, to_select, selected)
    if #selected == 0 then return true end
    return table.every(selected, function(id)
      return Fk:getCardById(id).type ~= Fk:getCardById(to_select).type
    end) and #selected < 3
  end,
}
Fk:addSkill(floodAttackCardSkillViewAs)
local floodAttackCardSkill = fk.CreateActiveSkill{
  name = "flood_attack_skill",
  prompt = "#flood_attack_skill",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    local to = Fk:currentRoom():getPlayerById(to_select)
    local from = Fk:currentRoom():getPlayerById(user)
    return user ~= to_select and not from:prohibitUse(Fk:cloneCard("slash")) 
    and not from:isProhibited(to, Fk:cloneCard("slash")) and not from:prohibitUse(card)
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local to_discard
    local _, ret = room:askForUseActiveSkill(from, "flood_attack_skill_viewas", "#flood_attack-select", false)
    if ret then
      to_discard = ret.cards
    end
    room:throwCard(to_discard, self.name, from, from)
    if not from.dead and not from:prohibitUse(Fk:cloneCard("slash")) 
    and not from:isProhibited(to, Fk:cloneCard("slash")) then
      local slash = Fk:cloneCard("water__slash")
      room:useCard({
        from = from.id,
        tos = {{to.id}},
        card = slash,
        additionalDamage = #to_discard - 1,
        extraUse = true, 
      })
    end
  end
}
local floodAttack = fk.CreateTrickCard{
  name = "flood_attack",
  skill = floodAttackCardSkill,
  is_damage_card = true,
  suit = Card.Diamond,
  number = 13,
}
Fk:loadTranslationTable{
  [":flood_attack"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名其他角色<br /><b>效果</b>：你弃置一至三张类别各不相同的"..
  "牌，然后视为对目标使用一张伤害基数为X的水【杀】（X为你以此法弃置的牌数）。",
  ["#flood_attack_skill"] = "纵水：选择一名其他角色",
  ["#flood_attack-select"] = "请选择至多三种类别各不相同的牌",
  ["flood_attack_skill_viewas"] = "纵水",
}
extension:addCards{
  floodAttack:clone(Card.Spade, 10),
  floodAttack:clone(Card.Club, 3),
  floodAttack:clone(Card.Club, 4),
}
local chainBarrierTrigger = fk.CreateTriggerSkill{
  name = "chain_barrier_trigger",
  anim_type = "defensive",
  mute = true,
  global = true,
  priority = 0.1,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target== player and data.card.type ~= Card.TypeEquip then
      if not target.chained then
        return table.find(player:getCardIds(Player.Hand), function(id)
          return Fk:getCardById(id).name == "chain_barrier"
        end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      local use = player.room:askForUseCard(player, "chain_barrier", nil, "#chain_barrier-ask:::" .. data.card:toLogString() , true, nil, data)
      if use then
        self.cost_data = use
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    use.from = player.id
    use.toCard = data.card
    use.responseToEvent = data
    room:useCard(use)
  end,
}
Fk:addSkill(chainBarrierTrigger)
local chainBarrierSkill = fk.CreateActiveSkill{
  name = "chain_barrier_skill",
  can_use = Util.FalseFunc,
  on_use = function() RoomInstance:delay(500) end,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if not player.chained then
      player:setChainState(true)
    end
    local card = effect.toCard
    if card.type == Card.TypeTrick and not card:isCommonTrick() then
      room:moveCardTo(card.id, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
    elseif effect.responseToEvent then
      table.insertIfNeed(effect.responseToEvent.nullifiedTargets, player.id)
    end
  end,
}
local chainBarrier = fk.CreateTrickCard{
  name = "chain_barrier",
  skill = chainBarrierSkill,
  special_skills = { "recast" },
  suit = Card.Diamond,
  number = 13,
}
addTaolueCard(chainBarrier:clone(Card.Club, 10))
addTaolueCard(chainBarrier:clone(Card.Club, 12))
addTaolueCard(chainBarrier:clone(Card.Club, 13))
addTaolueCard(chainBarrier:clone(Card.Spade, 11))
Fk:loadTranslationTable{
  ["chain_barrier_trigger"] = "铁索横江",
  [":chain_barrier"] = "锦囊牌<br /><b>时机</b>：成为【杀】或锦囊牌的目标后<br /><b>目标</b>：目标牌<br /><b>效果</b>：若你未横置，"..
  "你横置，然后此牌对你无效。（若为延时锦囊牌则将其置入弃牌堆）",
  ["#chain_barrier-ask"] = "是否使用【铁索横江】，横置并令%arg对你无效？",
}

local attackTheUnpreparedSkill = fk.CreateActiveSkill{
  name = "attacktheunprepared_skill",
  prompt = "#attacktheunprepared_skill",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    local to = Fk:currentRoom():getPlayerById(to_select)
    local from = Fk:currentRoom():getPlayerById(user)
    return user ~= to_select and (to:getEquipment(Card.SubtypeArmor) or #to:getPile("taolue") > 0)
  end,
  target_filter = function(self, to_select, selected, _, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local from = room:getPlayerById(effect.from)
    local card = room:askForCard(to, 1, 1, false, self.name, true, "jink", "#attacktheunprepared-ask:"..from.id)
    if #card > 0 then
      room:obtainCard(from, card, true, fk.ReasonGive, to.id)
    else
      local cards = {}
      if to:getEquipment(Card.SubtypeArmor) then
        table.insertIfNeed(cards, to:getEquipment(Card.SubtypeArmor))
      end
      if #to:getPile("taolue") > 0 then
        for _, id in ipairs(to:getPile("taolue")) do
          table.insertIfNeed(cards, id)
        end
      end
      if #cards > 1 then
        room:fillAG(to, cards)
        local cid = room:askforAG(to, cards, false, "attacktheunprepared")
        room:closeAG(to)
        if cid then
          room:obtainCard(from, cid, true, fk.ReasonGive, to.id)
        end
      elseif #cards == 1 then
        room:obtainCard(from, cards[1], true, fk.ReasonGive, to.id)
      end
    end
  end
}
local attackTheUnprepared = fk.CreateTrickCard{
  name = "attacktheunprepared",
  skill = attackTheUnpreparedSkill,
  suit = Card.Diamond,
  number = 13,
}
extension:addCards{
  attackTheUnprepared:clone(Card.Spade, 12),
  attackTheUnprepared:clone(Card.Spade, 13),
  attackTheUnprepared:clone(Card.Diamond, 12),
  attackTheUnprepared:clone(Card.Heart, 13),
}
Fk:loadTranslationTable{
  ["attacktheunprepared_skill"] = "攻其无备",
  ["#attacktheunprepared_skill"] = "使用攻其无备，选择一名装备区里有防具牌/体力牌旁有“韬略”牌的其他角色",
  [":attacktheunprepared"] = "锦囊牌<br /><b>时机</b>：成为【杀】或锦囊牌的目标后<br /><b>目标</b>：目标牌<br /><b>效果</b>：出牌阶段，"..
  "对一名装备区里有防具牌/体力牌旁有“韬略”牌的其他角色使用。目标角色需交给你一张【闪】，否则将该防具牌/体力牌旁的一张“韬略”牌交给你。",
  ["#attacktheunprepared-ask"] = "攻其无备：交给 %src 一张【闪】;或点击取消，然后将防具或一张“韬略”牌交给 %src",
}
local fallenHeroSkill = fk.CreateActiveSkill{
  name = "fallenhero_skill",
  prompt = "#fallenhero_skill",
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, _, card)
    return #selected == 0 and self:modTargetFilter(to_select, selected, Self.id, card, true)
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local judge = {
      who = to,
      reason = "fallenhero",
      pattern = ".|.|.",
    }
    room:judge(judge)
    local result = {judge.card:getSuitString(), judge.card:getTypeString()}
    room:setPlayerMark(to, "@fallenhero-turn", result)
    if not to:hasSkill("#fallenhero_prohibit") then
      room:handleAddLoseSkills(to, "#fallenhero_prohibit")
      room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
        if to:hasSkill("#fallenhero_prohibit") then
        room:handleAddLoseSkills(to, "-#fallenhero_prohibit")
        end
      end)
    end
    self:onNullified(room, effect)
  end,
  on_nullified = function(self, room, effect)
    room:moveCards{
      ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonUse
    }
  end,
}
local fallenHeroProhibit = fk.CreateProhibitSkill{
  name = "#fallenhero_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@fallenhero-turn") == 0 then return end
    if table.contains(player:getMark("@fallenhero-turn"), card:getSuitString()) 
    or table.contains(player:getMark("@fallenhero-turn"), card:getTypeString()) then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
      end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@fallenhero-turn") == 0 then return end
    if table.contains(player:getMark("@fallenhero-turn"), card:getSuitString()) 
    or table.contains(player:getMark("@fallenhero-turn"), card:getTypeString()) then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
      end)
    end
  end,
  prohibit_discard = function(self, player, card)
    if player:getMark("@fallenhero-turn") == 0 then return end
    return table.contains(player:getMark("@fallenhero-turn"), card:getSuitString()) 
    or table.contains(player:getMark("@fallenhero-turn"), card:getTypeString())
  end,
}
Fk:addSkill(fallenHeroProhibit)
local fallenHero = fk.CreateDelayedTrickCard{
  name = "fallenhero",
  skill = fallenHeroSkill,
  suit = Card.Diamond,
  number = 13,
}
extension:addCards{
  fallenHero:clone(Card.Spade, 4),
  fallenHero:clone(Card.Club, 11),
}
Fk:loadTranslationTable{
  ["fallenhero_skill"] = "将星陨落",
  [":fallenhero"] = "延时锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名其他角色<br /><b>效果</b>：将此牌置于目标角色的判定区里，"..
  "该角色于回合内不能使用、打出或弃置与判定牌花色或类别相同的牌。",
  ["#fallenhero_skill"] = "选择一名其他角色，将此牌置于其判定区内。该角色于回合内不能使用、打出或弃置与判定牌花色或类别相同的牌。",
  ["@fallenhero-turn"] = "将星",
}
local tigerSpearSkill = fk.CreateActiveSkill{
  name = "tiger_spear_skill",
  attached_equip = "tiger_spear",
  target_num = 0,
  card_num = 0,
  can_use = function (self, player)
    if player:usedSkillTimes(self.name) == 0 and not player:prohibitUse(Fk:cloneCard("slash")) then
      return table.every(player:getCardIds(Player.Hand), function(id)
        return Fk:getCardById(id).trueName ~= "slash"
      end)
    end
  end,
  target_filter = Util.FalseFunc,
  card_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:showCards(player.player_cards[Player.Hand])
    local card = Fk:cloneCard("slash")
    if not player:prohibitUse(card) then
      --[[local targets = table.map(table.filter(room.alive_players, function(p)
        return player:inMyAttackRange(p) and not player:isProhibited(p, card)
      end), Util.IdMapper)
      if #targets > 0 then
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#tiger_spear-ask", self.name, true)
        room:useVirtualCard("slash", nil, player, to, self.name, false)
      end]]
      local success, dat = room:askForUseActiveSkill(player, "tiger_spear_viewas", "#tiger_spear-ask", true)
      if success then
        local card = Fk.skills["tiger_spear_viewas"]:viewAs(dat.cards)
        card.trueName = "slash"
        room:useCard{
          from = player.id,
          tos = table.map(dat.targets, function(id) return {id} end),
          card = card,
        }
      end
    end
  end
  }
local tigerSpearViewas = fk.CreateViewAsSkill{ 
  name = "tiger_spear_viewas",
  pattern = "slash",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard("slash")
    card.skillName = "tiger_spear_skill"
    return card
  end,
}
Fk:addSkill(tigerSpearViewas)
Fk:addSkill(tigerSpearSkill)
local tigerSpear = fk.CreateWeapon{
  name = "tiger_spear",
  suit = Card.Diamond,
  number = 1,
  attack_range = 3,
  equip_skill = tigerSpearSkill,
}
extension:addCard(tigerSpear)
Fk:loadTranslationTable{
  
  ["#tiger_spear-ask"] = "虎头湛金枪：选择一名角色，视为对其使用一张【杀】",
  [":tiger_spear"] = "装备牌·武器<br/><b>攻击范围</b>：3<br/><b>武器技能</b>：出牌阶段限一次，你可以展示所有手牌，若其中没有【杀】，你视为使用一张【杀】（计入次数）",
  ["tiger_spear_skill"] = "湛金枪",
  ["#tiger_spear_skill"] = "出牌阶段限一次，你可以展示所有手牌，若其中没有【杀】，你视为使用一张【杀】（计入次数）",
  [":tiger_spear_skill"] = "出牌阶段限一次，你可以展示所有手牌，若其中没有【杀】，你视为使用一张【杀】（计入次数）",
  ["tiger_spear_viewas"] = "虎头湛金枪",
}
local taipingFlagSkill = fk.CreateTriggerSkill{
  name = "#taiping_flag_skill",
  attached_equip = "taiping_flag",
  events = { fk.AfterCardUseDeclared },
  can_trigger = function(self, _, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and data.card.name == "slash"
  end,
  on_cost = function (self, event, target, player, data)
    local all_choices = {"thunder__slash", "water__slash"}
    local choices = table.simpleClone(all_choices)
    table.removeOne(choices, data.card.name)
    if #choices > 0 and player.room:askForSkillInvoke(player, self.name) then
      local choice = player.room:askForChoice(player, choices, self.name, nil, false, all_choices)
      self.cost_data = choice
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local card = Fk:cloneCard(self.cost_data, data.card.suit, data.card.number)
    for k, v in pairs(data.card) do
      if card[k] == nil then
        card[k] = v
      end
    end
    if data.card:isVirtual() then
      card.subcards = data.card.subcards
    else
      card.id = data.card.id
    end
    card.skillNames = data.card.skillNames
    card.skillName = "#taiping_flag_skill"
    data.card = card
  end,
}
Fk:addSkill(taipingFlagSkill)
local taipingFlag = fk.CreateWeapon{
  name = "taiping_flag",
  suit = Card.Spade,
  number = 1,
  attack_range = 4,
  equip_skill = taipingFlagSkill,
}
addTaolueCard(taipingFlag)
Fk:loadTranslationTable{
  ["#taiping_flag_skill"] = "太平道旗",
  [":taiping_flag"] = "装备牌·武器<br/><b>攻击范围</b>：4<br/><b>武器技能</b>：当你使用普通【杀】时，你可以将此【杀】改为雷【杀】或改为水【杀】。",
}

local qianghuMaskSkill = fk.CreateTriggerSkill{
  name = "#qianghu_mask_skill",
  attached_equip = "qianghu_mask",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pattern = ".|1~"..(data.card.number - 1)
    local judge = {
      who = room:getPlayerById(data.from),
      reason = self.name,
      pattern = pattern,
    }
    room:judge(judge)
    if judge.card.number < data.card.number then
      table.insertIfNeed(data.nullifiedTargets, player.id)
    end
  end,
}
Fk:addSkill(qianghuMaskSkill)
local qianghuMask = fk.CreateArmor{
  name = "qianghu_mask",
  suit = Card.Club,
  number = 1,
  equip_skill = qianghuMaskSkill,
}
addTaolueCard(qianghuMask)
Fk:loadTranslationTable{
  ["#qianghu_mask_skill"] = "羌胡面具",
  [":qianghu_mask"] = "装备牌·防具<br/><b>武器技能</b>：当你成为【杀】的目标后，"..
  "你可以令此【杀】的使用者进行一次判定，若判定牌的点数小于此【杀】，则此【杀】对你无效。",
}

local cuffedArmorSkill = fk.CreateTriggerSkill{
  name = "#cuffed_armor_skill",
  attached_equip = "cuffed_armor",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and data.card.trueName == "slash" then
      return table.contains(TargetGroup:getRealTargets(data.tos), player.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = room:getPlayerById(data.from)
    if not player.dead and not from.dead then
      local use = room:askForUseCard(from, "slash", nil, "#cuffed_armor-ask:"..player.id, true, 
      { must_targets = targets, bypass_distances = true, bypass_times = true })
      if use then
        local subcards = Card:getIdList(use.card)
        if #subcards > 0 then
          local clonecards = Card:getIdList(data.card)
          local card = Fk:cloneCard(data.card.name, data.card.suit, data.card.number)
          for k, v in pairs(data.card) do
            if card[k] == nil then
              card[k] = v
            end
          end
          local origin_cards = {}
          if #clonecards > 0 then
            for _, c in ipairs(clonecards) do
              table.insertIfNeed(origin_cards, c)
            end
          end
          for _, c in ipairs(subcards) do
            table.insertIfNeed(origin_cards, c)
          end
          card.subcards = origin_cards
          card.skillNames = data.card.skillNames
          card.skillName = self.name
          data.card = card
          
          room:moveCardTo(data.card, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true)
        end
      else
        room:broadcastPlaySound("./packages/maneuvering/audio/card/vine")
        TargetGroup:removeTarget(data.tos, player.id)
      end
    end
  end
}
Fk:addSkill(cuffedArmorSkill)
local cuffedArmor = fk.CreateArmor{
  name = "cuffed_armor",
  suit = Card.Club,
  number = 2,
  equip_skill = cuffedArmorSkill,
}
extension:addCards{
  cuffedArmor,
  cuffedArmor:clone(Card.Spade, 2),
}
Fk:loadTranslationTable{
  ["#cuffed_armor_skill"] = "筒袖铠",
  [":cuffed_armor"] = "装备牌·防具<br/><b>武器技能</b>：锁定技，其他角色使用【杀】指定你为目标时，需要额外使用一张【杀】转化此【杀】，"..
  "否则取消之。",
  ["#cuffed_armor-ask"] = "筒袖铠：你需要额外使用一张【杀】，否则此【杀】对 %src 无效。",
}

local huiyingSkill = fk.CreateTriggerSkill{
  name = "#huiying_skill",
  attached_equip = "huiying",
  events = {fk.DrawNCards, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (event == fk.DrawNCards
     or (event == fk.EventPhaseStart and player.phase == Player.Finish))
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.DrawNCards then 
      if player.room:askForSkillInvoke(player, self.name) then
        data.n = data.n + 1
        player.room:addPlayerMark(player, "huiying-turn", 1)
        return true
      end
    else
      return player:getMark("huiying-turn") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart and player.phase == Player.Finish then
      local num = player:getMark("huiying-turn")
      if num > 0 then
        player.room:setPlayerMark(player, "huiying-turn", 0)
        player.room:askForDiscard(player, num, num, true, self.name, false)
      end
    end
  end,
}
Fk:addSkill(huiyingSkill)
local huiying = fk.CreateOffensiveRide{
  name = "huiying",
  suit = Card.Spade,
  number = 5,
  equip_skill = huiyingSkill,
}
extension:addCard(huiying)
Fk:loadTranslationTable{
  ["#huiying_skill"] = "灰影",
  [":huiying"] = "装备牌·坐骑<br /><b>坐骑技能</b>：你与其他角色的距离-1。摸牌阶段，你可以多摸一张牌，若如此做，结束阶段，你弃置一张牌。",
}

local warshipSkill = fk.CreateTriggerSkill{
  name = "#warship_skill",
  attached_equip = "warship",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and data.damageType == "water_damage"
    else
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerEquip then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).sub_type == Card.SubtypeOffensiveRide then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      if data.damage > 0 then
        data.damage = data.damage - 1
        return true
      end
    else
      local card = player:getEquipment(Card.SubtypeDefensiveRide)
      if card and Fk:getCardById(card).name == "warship" then
        player.room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
      end
    end
  end
}
Fk:addSkill(warshipSkill)
local warship = fk.CreateDefensiveRide{
  name = "warship",
  suit = Card.Diamond,
  number = 13,
  equip_skill = warshipSkill,
  on_install = function(self, room, player)
    DefensiveRide.onInstall(self, room, player) 
    if player:isAlive() then
      local card = player:getEquipment(Card.SubtypeOffensiveRide)
      if card then
        player.room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
      end
    end
  end,
}
addTaolueCard(warship)
Fk:loadTranslationTable{
  ["#warship_skill"] = "战船",
  [":warship"] = "装备牌·坐骑<br /><b>坐骑技能</b>：其他角色与你的距离+1。【战船】与进攻坐骑牌在装备区里互斥；你受到的水属性伤害-1。",
}

local pocketStratagemViewas = fk.CreateViewAsSkill{
  name = "pocket_stratagem_viewas",
  pattern = ".",
  interaction = function()
    local names = {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeBasic or card:isCommonTrick() then
        table.insertIfNeed(names, card.name)
      end
    end
    return UI.ComboBox {choices = names}
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player)
    local room = player.room
    room:addPlayerMark(player, "@pocket_stratagem_history", 1)
    room:setPlayerMark(player, "pocket_stratagem_limit-turn", 1)
  end,
  enabled_at_play = function(self, player)
    return player:getMark("pocket_stratagem_limit-turn") == 0
  end,
  enabled_at_response = function(self, player)
    return player:getMark("pocket_stratagem_limit-turn") == 0
  end,
  after_use = function(self, player)
    local room = player.room
    if player:getMark("@pocket_stratagem_history") >= 3 then 
      room:setPlayerMark(player, "@pocket_stratagem_history", 0)
      local cid = player:getEquipment(Card.SubtypeTreasure)
      if cid then
        if Fk:getCardById(cid).name == "pocket_stratagem" then
          room:throwCard(cid, "pocket_stratagem_viewas", player, player)
        end
      end
    end
  end,
}
local pocketStratagemTrigger = fk.CreateTriggerSkill{
  name = "#pocket_stratagem_trigger",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and player:getMark("pocket_stratagem_limit-turn") == 0 then
      return data.card.type ~= Card.TypeEquip and not target.chained and not player:prohibitUse(Fk:cloneCard("chain_barrier"))
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#pocket_stratagem_trigger-ask")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@pocket_stratagem_history", 1)
    room:setPlayerMark(player, "pocket_stratagem_limit-turn", 1)
    local use = {}
    local card = Fk:cloneCard("chain_barrier")
    use.from = player.id
    use.toCard = data.card
    card.skillName = "pocket_stratagem_viewas"
    use.card = card
    use.responseToEvent = data
    room:useCard(use)
    if player:getMark("@pocket_stratagem_history") >= 3 then 
      room:setPlayerMark(player, "@pocket_stratagem_history", 0)
      local cid = player:getEquipment(Card.SubtypeTreasure)
      if cid then
        if Fk:getCardById(cid).name == "pocket_stratagem" then
          room:throwCard(cid, "pocket_stratagem_viewas", player, player)
        end
      end
    end
  end,
}
local pocketStratagemMove = fk.CreateTriggerSkill{
  name = "#pocket_stratagem_move",
  events = {fk.BeforeCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and player:getMark("pocket_stratagem_limit-turn") == 0 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerEquip then
              self.cost_data = {table.indexOf(data, move), table.indexOf(move.moveInfo, info)}
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#pocket_stratagem_move-ask")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #self.cost_data > 0 then
      room:addPlayerMark(player, "@pocket_stratagem_history", 1)
      room:setPlayerMark(player, "pocket_stratagem_limit-turn", 1)
      return true
    end
    if player:getMark("@pocket_stratagem_history") >= 3 then 
      room:setPlayerMark(player, "@pocket_stratagem_history", 0)
      local cid = player:getEquipment(Card.SubtypeTreasure)
      if cid then
        if Fk:getCardById(cid).name == "pocket_stratagem" then
          room:throwCard(cid, "pocket_stratagem_viewas", player, player)
        end
      end
    end
  end
}
Fk:addSkill(pocketStratagemViewas)
Fk:addSkill(pocketStratagemTrigger)
Fk:addSkill(pocketStratagemMove)
local pocketStratagem = fk.CreateTreasure{
  name = "pocket_stratagem",
  suit = Card.Heart,
  number = 1,
  equip_skill = pocketStratagemViewas,
  on_install = function(self, room, player)
    Treasure.onInstall(self, room, player)
    local room = player.room 
    if not player:hasSkill("#pocket_stratagem_trigger") then
      room:handleAddLoseSkills(player, "#pocket_stratagem_trigger")
    end
    if not player:hasSkill("#pocket_stratagem_move") then
      room:handleAddLoseSkills(player, "#pocket_stratagem_move")
    end
    room:setPlayerMark(player, "@pocket_stratagem_history", 0)
  end,
  on_uninstall = function(self, room, player)
    Treasure.onUninstall(self, room, player)
    local room = player.room 
    if player:hasSkill("#pocket_stratagem_trigger") then
      room:handleAddLoseSkills(player, "-#pocket_stratagem_trigger")
    end
    if player:hasSkill("#pocket_stratagem_move") then
      room:handleAddLoseSkills(player, "-#pocket_stratagem_move")
    end
    room:setPlayerMark(player, "@pocket_stratagem_history", 0)
  end
}
Fk:loadTranslationTable{
  ["#pocket_stratagem_skill"] = "藏计锦囊",
  [":pocket_stratagem"] = "装备牌·宝物<br/><b>宝物技能</b>："..
  "每回合限一次，你可以在对应的时机执行以下一项："..
  "<br/>1.在需要时视为使用或打出任意基本牌；"..
  "<br/>2.在需要时视为使用任意普通锦囊牌；"..
  "<br/>3.当你装备区里的牌被移动时，防止之。"..
  "<br/>当你累计发动上述效果三次后，你弃置装备区里的【藏计锦囊】。",
  ["pocket_stratagem_basicresponse"] = "藏计锦囊",
  ["@pocket_stratagem_history"] = "藏计锦囊",
  ["pocket_stratagem_viewas"] = "藏计",
  ["#pocket_stratagem_viewas"] = "选择使用牌的牌名",
  ["#pocket_stratagem_trigger"] = "藏计锦囊",
  ["#pocket_stratagem_trigger-ask"] = "藏计锦囊：是否视为使用“铁索横江”？",
  ["#pocket_stratagem_move"] = "藏计锦囊",
  ["#pocket_stratagem_move-ask"] = "藏计锦囊：是否防止此次装备区内牌的移动？",
  [":pocket_stratagem_viewas"] = "每回合限一次，你可以在对应的时机执行以下一项："..
  "<br/>1.在需要时视为使用或打出任意基本牌；"..
  "<br/>2.在需要时视为使用任意普通锦囊牌；"..
  "<br/>3.当你装备区里的牌被移动时，防止之。"..
  "<br/>当你累计发动上述效果三次后，你弃置装备区里的【藏计锦囊】。",
}
addTaolueCard(pocketStratagem)


--[[
local militaryStrategySkill = fk.CreateActiveSkill{
  name = "military_strategy_skill&",
  prompt = "#military_strategy_skill&",
  anim_type = "deffense",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return #player:getPile("taolue") > 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = player:getPile("taolue")
    room:fillAG(player, cards)
    local cid = room:askforAG(player, cards, false, self.name)
    room:closeAG(player)
    if cid then
      room:moveCardTo(cid, Card.DiscardPile, player, Fk.ReasonJustMove, self.name)
      room:addSkill
      room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
        if to:hasSkill("#fallenhero_prohibit") then
        room:handleAddLoseSkills(to, "-#fallenhero_prohibit")
        end
      end)
    end
  end,
}
local militaryStrategRrule = fk.CreateTriggerSkill{
  name = "#military_strategy_rule",
  priority = 0.001,
  global = true,

  refresh_events = {fk.GamePrepared},
  can_refresh = function(self, event, target, player, data)
    return not table.contains(player.room.disabled_packs, "starjade_cards")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:handleAddLoseSkills(p, "military_strategy_skill&", nil, false, true)
    end
    for _, card in ipairs(Fk.packages["starjade_cards"].cards) do
      if table.contains(MilitaryStrategyCards, card) then
        room:setCardMark(card, "@@military_strategy", 1)
      end
    end
  end,
}


militaryStrategySkill:addRelatedSkill(militaryStrategyTrigger)
Fk:addSkill(militaryStrategySkill)
Fk:addSkill(militaryStrategRrule)
]]

Fk:loadTranslationTable{
  ["sjade_shot__slash"] = "射杀",
  ["sjade__talisman"] = "符",
  ["flood_attack"] = "纵水",
  ["tiger_spear"] = "虎头湛金枪",
  ["taiping_flag"] = "太平道旗",
  ["qianghu_mask"] = "羌胡面具",
  ["cuffed_armor"] = "筒袖铠",
  ["chain_barrier"] = "铁索横江",
  ["fallenhero"] = "将星陨落",
  ["huiying"] = "灰影",
  ["pocket_stratagem"] = "藏计锦囊",
  ["warship"] = "战船",
  ["attacktheunprepared"] = "攻其无备",
  ["military_strategy"] = "韬略",
  ["@@military_strategy"] = "<font color='yellow'>韬略</font>",
  ["military_strategy_skill&"] = "韬略",
  [":military_strategy_skill&"] = "出牌阶段限一次，你可以将武将牌旁的任意张“韬略”牌弃置。若如此做，你于本回合下一次使用牌造成的伤害+X（X为此阶段你弃置的武将牌旁的“韬略”牌数）。结束阶段，你可以将一张有“韬略”标记的牌置于武将牌旁。你武将牌旁至多有两张“韬略”。当你对另一名武将牌旁有“韬略”牌的角色造成伤害时，你可以令此次伤害-Y，然后弃置受伤角色武将牌旁的Y张“韬略”牌（Y不大于受伤角色武将牌旁已有的“韬略”牌数）。",
}

return extension